package org.genntii.warehousesystem.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.genntii.warehousesystem.common.Result;
import org.genntii.warehousesystem.domain.entity.Brand;
import org.genntii.warehousesystem.service.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌接口",
        description = "用于管理品牌，对于品牌的增删查")
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Resource
    private BrandService brandService;

    @Operation(summary = "增添品牌")
    @Parameter(name = "brand",description = "品牌名称",required = true,in = ParameterIn.QUERY)
    @PostMapping("/v1/add")
    public Result add(@RequestParam("brand")String brand){
        brandService.add(brand);
        return Result.success();
    }

    @Operation(summary = "删除品牌")
    @Parameter(name = "id",description = "品牌id",required = true,in = ParameterIn.QUERY)
    @DeleteMapping("/v1/del")
    public Result del(@RequestParam("id")int id){
        brandService.del(id);
        return Result.success();
    }

    @Operation(summary = "分页获取品牌列表")
    @Parameter(name = "page",description = "页码",required = true,in = ParameterIn.QUERY)
    @GetMapping("/v1/getBrand")
    public Result<List<Brand>> getBrandByPage(@RequestParam("page")int page){
        return Result.success(brandService.showAllByPage(page));
    }

    @Operation(summary = "获取品牌")
    @GetMapping("/getBrand")
    public Result<List<Brand>> getBrand(){
        return Result.success(brandService.showAllBrand());
    }

}
